package com.biz.primus.auth.controller;

import com.biz.primus.common.utils.JsonUtils;
import com.biz.primus.account.feign.AuthorityFeignClient;
import com.biz.primus.management.base.controller.AbstractBaseController;
import com.biz.primus.model.sso.auth.vo.MenusRegisterReqVO;
import com.biz.primus.model.sso.auth.vo.MenusRegisterResVO;
import com.biz.primus.model.sso.auth.vo.UserAuthoritiesReqVO;
import com.biz.primus.model.sso.auth.vo.UserAuthoritiesResVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 服务菜单及权限模块 Controller
 * Created by defei on 8/1/17.
 */
@RestController
@RequestMapping("primus/authorities")
public class AuthorityController extends AbstractBaseController {

    private static final Logger logger = LoggerFactory.getLogger(AuthorityController.class);

    private final AuthorityFeignClient authorityFeignClient;

    @Autowired
    public AuthorityController(AuthorityFeignClient authorityFeignClient) {
        this.authorityFeignClient = authorityFeignClient;
    }


    @RequestMapping(method = RequestMethod.GET)
    public UserAuthoritiesResVO getUserAuthorities(@RequestParam("data") String data) {

        logger.info("Received /authorities.do GET request with data:{}.", data);
        UserAuthoritiesReqVO reqVO = JsonUtils.json2Obj(data, UserAuthoritiesReqVO.class);
        return authorityFeignClient.getUserAuthorities(reqVO.getUserUnionId());
    }

}
